﻿using FastExecutor.Base.Design;
using FastExecutor.Base.Util;
using FastExecutor.ORG.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FastExecutor.ORG.DB
{
    public class DB_AttachConfig : FastTemplateDB<Frame_AttachConfig>
    {
        public override void Insert(Frame_AttachConfig Entity)
        {
            //附件库只能有一个处于启用状态
            if (Entity.IsEnable == 1)
            {

                string sql = "update frame_attachconfig set isenable = 0";
                @DBUtil.ExecuteSQL(sql);
            }
            Entity.RowGuid = CommonUtil.CreateCommonGuid();
            Entity.AddDate = DateTime.Now;
            base.Insert(Entity);
        }

        public override void Update(Newtonsoft.Json.Linq.JObject JsonEntity)
        {
            //附件库只能有一个处于启用状态
            if (Convert.ToInt32(JsonEntity.GetValue("IsEnable")) == 1)
            {
                string sql = "update frame_attachconfig set isenable = 0";
                @DBUtil.ExecuteSQL(sql);
            }
            base.Update(JsonEntity);
        }

    }
}
